<?php
namespace Home\Model;
use Think\Model;
use Common\Library\Category;
class ArticleCategoryModel extends Model{
	private $DescriptionModel;
	function _initialize(){
		parent::_initialize();
		$this->DescriptionModel=M('ArticleCategoryDescription');
	}

	public function getArticleCategory($article_category_id){
		$map=array('article_category_id'=>(int)$article_category_id);
		$article_category=$this->where($map)->find();
		$map['language_id']=get_default_lng_id();
		$acd=$this->DescriptionModel->where($map)->find();		
		$article_category['article_category_description']=$acd;
		
		return $article_category;
	}
	/**
	 * 获取分类列表
	 */
	public function getArticleCategories($data=array()){
		$map=array(
			'language_id'	=>	get_default_lng_id(),
			'status'		=>	1
			);
		$order='sort_order ASC,article_category_id DESC';
		$article_categories=$this->join('LEFT JOIN  __ARTICLE_CATEGORY_DESCRIPTION__ ON __ARTICLE_CATEGORY__.article_category_id=__ARTICLE_CATEGORY_DESCRIPTION__.article_category_id')->where($map)->field(C('DB_PREFIX')."article_category.*,title,meta_title,meta_description,meta_description,meta_keyword,description")->order($order)->select();
		foreach ($article_categories as $k => $v) {
			$article_categories[$k]['url']=U('Article/index?article_category_id='.$v['article_category_id']);
		}
		return $article_categories;
	}
	public function getChildId($article_category_id){
		$cate=$this->select();
		$cate_ids=Category::getChildsId ($cate, $article_category_id,"article_category_id","parent_id");
		$cate_ids=array_merge(array($article_category_id),$cate_ids);		
		return $cate_ids;
	}

	public function getParents($article_category_id=0){
		$cates=$this->getArticleCategories();
		$return=Category::getParents($cates,$article_category_id,'article_category_id','parent_id');
		return $return;
	}
}